﻿using System.Runtime.Serialization;

namespace ServerUtils
{
    [DataContract]
    public class OperationResult
    {
        [DataMember]
        public string Message { get; set; }

        [DataMember]
        public OperationResultType ResultType { get; set; }

        public OperationResult()
        {
        }

        public static OperationResult Succeed
        {
            get
            {
                return new OperationResult { ResultType = OperationResultType.Succeed }; 
            }
        }

        public static OperationResult Failed(string message)
        {
            return new OperationResult { ResultType = OperationResultType.Failed, Message = message }; 
        }

        public static OperationResult Failed(string format, params object[] args)
        {
            return Failed(string.Format(format, args));
        }

        public static OperationResult Error(string message)
        {
            return new OperationResult { ResultType = OperationResultType.Error, Message = message };
        }

        public static OperationResult Error(string format, params object[] args)
        {
            return Error(string.Format(format, args));
        }

        public override string ToString()
        {
            return string.Format("ResultType: {0}, Message: {1}", this.ResultType, this.Message);
        }
    }
}
